/**
 * Description:
 * Class Name:WriteToProcess
 * Date:2022/5/2 15:56
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_6_Java虚拟机读写其他进程的数据;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

class ReadStandard{
    public static void main(String[] args) {
        try (
                var sc = new Scanner(System.in);
                var ps = new PrintStream(new FileOutputStream("Chapter_15_6_out.txt"))
                ){
            sc.useDelimiter("\n");
            while (sc.hasNext()){
//                String temp = sc.next();
//                if (!temp.equals("exit")){
//                    ps.println("键盘的输入内容是：" + temp);
//                }
//                else break;
                ps.println("键盘的输入内容是：" + sc.next());
            }
        }
        catch (IOException ioException){
            ioException.printStackTrace();
        }
    }
}

public class WriteToProcess {
    public static void main(String[] args) throws IOException {
        String class_path = ReadStandard.class.getName();
        Process p = Runtime.getRuntime().exec("java " + class_path);
        try (
                var ps = new PrintStream(p.getOutputStream())
                ){
            ps.println("普通字符串");
            ps.println(new WriteToProcess());
        }
    }
}
